from flask import request,Blueprint,jsonify,session,render_template
auth = Blueprint('auth', __name__)

@auth.before_request
def authAuthority():
    if session.get('curUser') == None:
        return render_template("405.html")
    else:
        pass
@auth.route('/index')
def index():
    curUser=session.get('curUser')
    return render_template("index.html",curUser=curUser)

@auth.route("/logout")
def logout():
    session.pop('curUser')
    return render_template("login.html")

@auth.route('/htmlView/<htmlView>')
def htmlView(htmlView):

    return render_template(htmlView)
@auth.route("/opinionData")
def getOpinionData():
    import backstage.opinion as opinion
    dict={
     "sourceType":request.args.get("sourceType"),
     "content":request.args.get("content"),
     "page":request.args.get("page"),
     "limit":request.args.get("limit"),
    }
    list=opinion.getDataByDataTypeAndContentlike(**dict)
    resp = {
        "code": 0,
        "msg": "",
        "data": list[0],
        "count": list[1]
    }
    return jsonify(resp)
@auth.route("/crawl")
def crawl():
    sourceType=request.args.get("sourceType")
    import  backstage.crawl as crawl
    crawl.doCrawl(sourceType)
    resp={
        "msg":"",
        "code":"200"
    }
    return jsonify(resp)